package com.wantup.demo03xd.part06.atomic;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author Zhaoluowei
 * @version 1.0
 * @date 2019/7/4 9:54
 */
public class Demo1 {

    private static AtomicInteger num = new AtomicInteger(0);

    public static void add() {
        num.getAndIncrement();
    }

    public static void main(String[] args) {

        for (int i = 0; i < 10; i++) {
            //创建10个线程
            new Thread(() -> {
                for (int j = 0; j < 100; j++) {
                    add();
                    System.out.println(num);
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }).start();

        }


    }


}
